<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class GiteePullerController extends Controller
{
    //
    public function pull(Request $request){
        $data=$request->all();
        $method=$request->header("X-Gitee-Event",null);
        $token=$request->header("X-Gitee-Token",null);
        if(empty($method)){
         return "empty event";
        }
        if(empty($token)){
         return "empty token";
        }
        if($token=="abcdefgzhideai521"){
            $dir=dirname(__DIR__);
            $dir=dirname($dir);
            $dir=dirname($dir);
            $sh=$dir.DIRECTORY_SEPARATOR."cd /www/wwwroot/online-shop && git pull origin-ssh dev";
            $log=$dir.DIRECTORY_SEPARATOR."pulllog.log";
            $str=PHP_EOL.PHP_EOL."【{$method}】".date("Y-m-d H:i:s").PHP_EOL;
            $s123=exec($sh,$data123);
            $str.=$s123.PHP_EOL.json_encode($data123).PHP_EOL;
            file_put_contents($log,$str,FILE_APPEND);
            IndexController::addGiteePullLog($data);
            return 'success';
        }
         return "error token";
    }
    public function pullTest(Request $request){
        $proejct=$request['project']??'';
        $proejctName=$proejct['name']??'';
        $v=$this->dispatch(new \App\Jobs\GiteePullerJob($proejctName));
        return 'success';
    }
}
